﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Utility;
using HotelMatchUtility.Utility;

namespace HotelMatchUtility.Entity
{
    public class HotelEntity : EqualityComparer<HotelEntity>, ICloneable
    {
        /// <summary>
        /// 是否被排除，比上后
        /// 如果IsExclusiveCondition =T 则下一次比较可以直接跳过 该酒店（表明已经被比上）
        /// </summary>
        public bool IsExclusive { get; set; }
        /// <summary>
        /// 已经匹配上的，需要直接输出
        /// </summary>
        public List<HotelEntity> FriendHotelList { get; set; }

        /// <summary>
        /// 精确匹配结果
        /// </summary>
        public List<HotelEntity> ExactMatchResult { get; set; }

        /// <summary>
        /// 模糊匹配
        /// </summary>
        public List<HotelEntity> SimilarMatchResult { get; set; }

        public HotelEntity()
        {
            FriendHotelList = new List<HotelEntity>();
            ExactMatchResult = new List<HotelEntity>();
            SimilarMatchResult = new List<HotelEntity>();
        }

        #region 实体内容
        public string MatchType { get; set; }

        public string PriceInfo { get; set; }

        private int hotel;

        public int Hotel
        {
            get { return hotel; }
            set { hotel = value; }
        }

        public string HotelCode
        { get; set; }

        private string hotelName;

        public string HotelName
        {
            get { return hotelName; }
            set { hotelName = value; }
        }

        private string hotelEnName;

        public string HotelEnName
        {
            get { return hotelEnName; }
            set { hotelEnName = value; }
        }

        private string address;

        public string Address
        {
            get { return address; }
            set { address = value; }
        }

        private string telephone;

        public string Telephone
        {
            get { return telephone; }
            set { telephone = value; }
        }

        private string zipCode;

        public string ZipCode
        {
            get { return zipCode; }
            set { zipCode = value; }
        }

        public string CityCode
        { get; set; }

        private int city;

        public int City
        {
            get { return city; }
            set { city = value; }
        }

        private string website;

        public string Website
        {
            get { return website; }
            set { website = value; }
        }

        private string cityName;

        public string CityName
        {
            get { return cityName; }
            set { cityName = value; }
        }

        public string CityEnName
        {
            get;
            set;
        }

        public string CountryCode
        { get; set; }

        private int country;

        public int Country
        {
            get { return country; }
            set { country = value; }
        }

        private string countryName;

        public string CountryName
        {
            get { return countryName; }
            set { countryName = value; }
        }

        public string CountryEnName
        { get; set; }

        private double glat;

        public double Glat
        {
            get { return glat; }
            set { glat = value; }
        }

        private double glon;

        public double Glon
        {
            get { return glon; }
            set { glon = value; }
        }

        private int vendorID;

        public int VendorID
        {
            get { return vendorID; }
            set { vendorID = value; }
        }

        private string vendorName;

        public string VendorName
        {
            get { return vendorName; }
            set { vendorName = value; }
        }

        public int HotelGroup { get; set; }

        public string HotelBelongTo { get; set; }

        public string HotelType { get; set; }

        public string HotelGroupName { get; set; }

        public string Bookable { get; set; }

        public string DistrictCodeBookingOrCtrip { get; set; }

        public string DistrictName { get; set; }

        public string DistrictEnName { get; set; }

        public int Province { get; set; }
        public string ProvinceEnName { get; set; }
        public string ProvinceName { get; set; }
        #endregion

        public bool HotelNameContainsAndAddressContains(HotelEntity ToCompareEntity)
        {
            string targetAddress = this.Address;
            string toCompareAddress = ToCompareEntity.Address;

            string targetHotelEname = this.HotelEnName;
            string toCompareHotelEname = ToCompareEntity.HotelEnName;

            if (string.IsNullOrEmpty(toCompareAddress) || string.IsNullOrEmpty(targetAddress)) return false;

            return
                (targetHotelEname.ToUpper().Replace(" ", "").Contains(toCompareAddress.ToUpper().Replace(" ", ""))
                || toCompareAddress.ToUpper().Replace(" ", "").Contains(targetHotelEname.ToUpper().Replace(" ", ""))
                )
                &&
                (targetHotelEname.ToUpper().Replace(" ", "").Contains(toCompareHotelEname.ToUpper().Replace(" ", ""))
                || toCompareHotelEname.ToUpper().Replace(" ", "").Contains(targetHotelEname.ToUpper().Replace(" ", ""))
                );
        }

        /// <summary>
        /// 返回两点之间的 距离数 1.234km这样
        /// </summary>
        /// <param name="ToCompareEntity"></param>
        /// <returns></returns>
        public double LonLatToKilometer(HotelEntity ToCompareEntity)
        {
            return GeoUtility.DistanceOfTwoPoints(this.Glon, this.Glat, ToCompareEntity.Glon, ToCompareEntity.Glat);
        }

        public bool TelephoneCompare(HotelEntity ToCompareEntity)
        {
            string targetTelephone = CommonUtility.FormatTelephone(this.Telephone);
            string toCompareTelephone = CommonUtility.FormatTelephone(ToCompareEntity.Telephone);

            if (targetTelephone == "" || toCompareTelephone == "")
                return false;
            return targetTelephone == toCompareTelephone;
        }

        public List<string> GetFormatAddress()
        {
            return CommonUtility.FormatNameOrAddress(this.Address);
        }

        public List<string> GetFormatName()
        {
            return CommonUtility.FormatNameOrAddress(this.HotelEnName);
        }



        public object Clone()
        {
            object ob = new HotelEntity();
            HotelEntity obEntity = (HotelEntity)ob;
            
            obEntity.MatchType = this.MatchType;
            obEntity.PriceInfo = this.PriceInfo;
            obEntity.Hotel = this.Hotel;
            obEntity.HotelCode = this.HotelCode;
            obEntity.HotelName = this.HotelName;
            obEntity.HotelEnName = this.HotelEnName;
            obEntity.Address = this.Address;
            obEntity.Telephone = this.Telephone;
            obEntity.ZipCode = this.ZipCode;
            obEntity.CityCode = this.CityCode;
            obEntity.City = this.City;
            obEntity.Website = this.Website;
            obEntity.CityName = this.CityName;
            obEntity.CityEnName = this.CityEnName;
            obEntity.CountryCode = this.CountryCode;
            obEntity.Country = this.Country;
            obEntity.CountryName = this.CountryName;
            obEntity.CountryEnName = this.CountryEnName;
            obEntity.Glat = this.Glat;
            obEntity.Glon = this.Glon;
            obEntity.VendorID = this.VendorID;
            obEntity.VendorName = this.VendorName;
            obEntity.HotelGroup = this.HotelGroup;
            obEntity.HotelBelongTo = this.HotelBelongTo;
            obEntity.HotelType = this.HotelType;
            obEntity.HotelGroupName = this.HotelGroupName;
            obEntity.Bookable = this.Bookable;
            obEntity.DistrictCodeBookingOrCtrip = this.DistrictCodeBookingOrCtrip;
            obEntity.DistrictName = this.DistrictName;
            obEntity.DistrictEnName = this.DistrictEnName;
            obEntity.Province = this.Province;
            obEntity.ProvinceEnName = this.ProvinceEnName;
            obEntity.ProvinceName = this.ProvinceName;

            return ob;

        }

        public override bool Equals(HotelEntity x, HotelEntity y)
        {
            return x.Hotel == y.Hotel;
        }

        public override int GetHashCode(HotelEntity obj)
        {
            throw new NotImplementedException();
        }
    }
}
